/**
 * 
 */
package org.tinygroup.bizframe.templatefunction;

import java.util.List;

import org.tinygroup.beancontainer.BeanContainerFactory;
import org.tinygroup.bizframe.service.inter.ParamService;
import org.tinygroup.bizframe.service.inter.dto.ParamDto;
import org.tinygroup.logger.LogLevel;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;
import org.tinygroup.template.Template;
import org.tinygroup.template.TemplateContext;
import org.tinygroup.template.TemplateEngine;
import org.tinygroup.template.TemplateException;
import org.tinygroup.template.TemplateFunction;

/**
 * @author Paul
 *
 */
public class ParamFunction implements TemplateFunction {

	private Logger logger = LoggerFactory.getLogger(ParamFunction.class);
	/* (non-Javadoc)
	 * @see org.tinygroup.template.TemplateFunction#getBindingTypes()
	 */
	public String getBindingTypes() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.tinygroup.template.TemplateFunction#getNames()
	 */
	public String getNames() {
		return "getSysParam";
	}

	/* (non-Javadoc)
	 * @see org.tinygroup.template.TemplateFunction#getTemplateEngine()
	 */
	public TemplateEngine getTemplateEngine() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see org.tinygroup.template.TemplateFunction#setTemplateEngine(org.tinygroup.template.TemplateEngine)
	 */
	public void setTemplateEngine(TemplateEngine templateEngine) {
		// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see org.tinygroup.template.TemplateFunction#execute(org.tinygroup.template.Template, org.tinygroup.template.TemplateContext, java.lang.Object[])
	 */
	public Object execute(Template template, TemplateContext context, Object... parameters) throws TemplateException {
		if(parameters==null || parameters.length==0){
			return null;
		}
		ParamService paramService= BeanContainerFactory.getBeanContainer(ParamFunction.class.getClassLoader()).getBean("paramServiceImpl");
		if(paramService == null){
			logger.logMessage(LogLevel.WARN, "服务不存在{0}","paramService");
		}
		ParamDto paramDto=new ParamDto() ;
		paramDto.setParamId(parameters[0].toString());
		List lsParams = paramService.getParamList(paramDto);
		if(lsParams!=null && lsParams.size()>0){
			return lsParams.get(0);
		}
		return null;
	}

}
